package com.example.idea.mapper;

import com.example.idea.entity.Notice;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NoticeMapper {

    @Select("insert into notice(title,content,userid,time,open) values(#{title},#{content},#{userid},#{time},#{open})")
    void add(Notice notice);

    void update(Notice notice);

    @Delete("delete from notice where id=#{id}")
    void delete(Integer id);

    @Select("select * from notice where id=#{id}")
    Notice query(Integer id);

    @Delete("delete from notice where id in (${ids})")
    void deleteBatch(String ids);

    @Select("select * from notice where open = 1 ORDER BY id DESC")
    List<Notice> list();

    List<Notice> selectList(Notice notice);

    @Select("select * from notice where title like concat('%',#{title},'%') and time like concat('%',#{time},'%') ORDER BY id DESC  limit #{skipNum},#{pageSize}")
    List<Notice> selectByPage(Integer skipNum, Integer pageSize, String title, String time);

    @Select("select count(*) from notice where title like concat('%',#{title},'%') and time like concat('%',#{time},'%')")
    Integer selectCountByPage(String title, String time);
}
